home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / newacct / newacct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-29  |  4.0 KB  |  152 lines

  1. /* 
  2.  * newacct.c --
  3.  *
  4.  *    Collect infomation on a new account request.
  5.  *      Make sure the information is valid.  Then mail it
  6.  *      to the staff.
  7.  *
  8.  * Copyright 1990 Regents of the University of California
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifndef lint
  19. static char rcsid[] = "$Header: /sprite/src/cmds/newacct/RCS/newacct.c,v 1.2 90/06/28 23:22:38 rab Exp $";
  20. #endif
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <ctype.h>
  25. #include <pwd.h>
  26. #include <grp.h>
  27.  
  28. #ifndef __STDC__
  29. #define const
  30. #endif
  31.  
  32. #define MAIL_WHO        "admin"
  33. #define BUFFER_SIZE     0x100
  34.  
  35. extern int  yes();
  36. extern void getString();
  37. extern void getPasswd();
  38. extern char *getShell();
  39. extern void mail();
  40.  
  41.  
  42. /*
  43.  *----------------------------------------------------------------------
  44.  *
  45.  * main --
  46.  *
  47.  *    Prompts the user for information needed to create a new
  48.  *      account.  Sticks all the info into a buffer and mails it
  49.  *      to the person who will create the account.
  50.  *
  51.  * Results:
  52.  *    None.
  53.  *
  54.  * Side effects:
  55.  *    Sends mail.
  56.  *
  57.  *----------------------------------------------------------------------
  58.  */
  59. void
  60. main()
  61. {
  62.     static char login_name[BUFFER_SIZE];
  63.     static char full_name[BUFFER_SIZE];
  64.     static char group[BUFFER_SIZE];
  65.     static char home_phone[BUFFER_SIZE];
  66.     static char office[BUFFER_SIZE];
  67.     static char office_phone[BUFFER_SIZE];
  68.     static char project[BUFFER_SIZE];
  69.     static char encrypted_passwd[BUFFER_SIZE];
  70.     static char machine[BUFFER_SIZE];
  71.     const char *shell;
  72.     char *p;
  73.     int y;
  74.     char buffer[0x1000];
  75.     struct group *grp;
  76.     struct passwd *pwd;
  77.  
  78.     for (;;) {
  79.     printf("Please enter the following information:\n");
  80.     for (;;) {
  81.         getString(":",  "Login name  ", login_name);
  82.         if ((pwd = getpwnam(login_name)) != NULL) {
  83.         char *p = pwd->pw_gecos;
  84.  
  85.         while (*p && *p != ',') {
  86.             ++p;
  87.         }
  88.         *p = '\0';
  89.         printf("Sorry, `%s' is already in use: %s\n",
  90.             login_name, pwd->pw_gecos);
  91.         continue;
  92.         }
  93.         break;
  94.     }
  95.     getString(":",  "Full name   ", full_name);
  96.     for (;;) {
  97.         getString(":",  "Group       ", group);
  98.         if (isdigit(*group)) {
  99.         grp = getgrgid(atoi(group));
  100.         } else {
  101.         grp = getgrnam(group);
  102.         }
  103.         if (grp == NULL) {
  104.         printf("%s is not a valid group\n", group);
  105.         printf("Please try again\n");
  106.         continue;
  107.         }
  108.         break;
  109.     }
  110.     getString(":,", "Office      ", office);
  111.     getString(":,", "Office phone", office_phone);
  112.     getString(":,", "Home phone  ", home_phone);
  113.     shell = getShell();
  114.     getPasswd(encrypted_passwd);
  115.     getString("",   "Project     ", project);
  116.     getString("",   "Machine to forward mail to", machine);
  117.     printf("\n\n\n");
  118.     printf("Login name:   %s\n", login_name);
  119.     printf("Full name:    %s\n", full_name);
  120.     printf("Group:        %s %d\n", grp->gr_name, grp->gr_gid);
  121.     printf("Office:       %s\n", office);
  122.     printf("Office phone: %s\n", office_phone);
  123.     printf("Home phone:   %s\n", home_phone);
  124.     printf("Shell:        %s\n", shell);
  125.     printf("Project:      %s\n", project);
  126.     printf("Mail forwarded to: %s\n", machine);
  127.     printf("\n");
  128.     if (yes("Is this correct?")) {
  129.         break;
  130.     }
  131.     }
  132.     sprintf(buffer,
  133.     "%s\n%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n",
  134.         "Request for New Account",
  135.         "-----------------------",
  136.     "Login name:   ", login_name,
  137.     "password:     ", encrypted_passwd,
  138.     "Full name:    ", full_name,
  139.     "Group:        ", grp->gr_name,
  140.     "Office:       ", office,
  141.     "Office phone: ", office_phone,
  142.     "Home phone:   ", home_phone,
  143.     "Shell:        ", shell,
  144.     "Project:      ", project,
  145.     "Mail forwarded to: ", machine);
  146.     printf("Sending mail to %s ...", MAIL_WHO);
  147.     mail(MAIL_WHO, buffer);
  148.     printf("\nThank you.  The account will be ready in a few days.\n");
  149.     exit(0);
  150. }
  151.  
  152.